﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PersonalAlbumModel>" %>
<%@ Import Namespace="MyAlbum.Model" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <span class="error"><%=Html.Encode(Model.ErrorMessage)%></span>
<%=Html.Tooltip(MyAlbum.Services.Configuration.ConfigValues.AlbumsPerRow)%>
        <%
            int itemPerRow = Math.Max(1, Model.Configuration.AlbumsPerRow);
            string width = ((90-itemPerRow*4) / itemPerRow).ToString()+"%";
            foreach(var item in Model.Albums)
            {
                Model.CurrentAlbum = item;
                %>
                <div style=" width:<%=width%>" class="albumBox">
                <%Html.RenderPartial("AlbumItem",Model); %>
                   
                    <%if (Model.User.AllowActions())
                      {%>
                      <%using (Html.BeginForm<AlbumsController>(a => a.Delete(item.Id), FormMethod.Post, new { id = "formDelete" + item.Id }))
                         { %>
                         <%=Html.Hidden("sectionId", item.ParentId)%>
                        <%=Html.Hidden("returnUrl", Request.RawUrl)%>
                         <%=Html.AntiForgeryToken()%>
                       <%} %>
                           <a href="javascript:void(0)" onclick="deleteAlbum('<%=item.Id %>')">   
                                 <img class="actionImage" src="<%=Html.ThemeItem("Delete.gif")%>" alt="<%=Model.Localize("Album.Delete") %>" title="<%=Model.Localize("Album.Delete") %>" />
                          </a>
                      &nbsp;
                         <a href="javascript:void(0)" onclick="showEditAlbum('<%=item.Id %>');return false">
                            <img class="actionImage" title="<%=Model.Localize("Edit") %>" src="<%=Html.ThemeItem("Edit.gif")%>" alt="<%=Model.Localize("Edit") %>" />
                        </a>
                <% }%>
              </div>
                <%}%>
                
    <%if (Model.User.AllowAdd())
    {%>
     <a href="javascript:void(0)" onclick="showAddAlbum();return false">
        <%=Model.Localize("Album.Add")%>
     </a>
    <%}%>
   
      <script type="text/javascript">
        function deleteAlbum(id) {
            if (confirm('<%=Model.Localize("Album.ConfirmDelete")%>')) {
                document.getElementById('formDelete' + id).submit();
            }
            return false;
        }
      </script>
       <% if (Model.User.AllowActions())
           {%>
  <script type="text/javascript">
           <!--
      function showAddAlbum() {
          $.ajax({
          url: '<%=Url.Action("ShowCreate","Albums",new{parentSection= Model.ParentSection}) %>',
              metehod: 'post',
              dataType: 'html',
              success: function(t) {
                   document.getElementById('editAlbumDivContent').innerHTML = t;
                   $('#AddAlbumForm').validate();
                   document.getElementById('editAlbumDivTopContent').innerHTML = '<%=Model.Localize("Album.Add") %>';
                  $('#editAlbumDiv').show();
                  document.getElementById('returnUrl').value = '<%=Html.Encode(Request.RawUrl) %>';
              }, error: function(err) {
                  alert('<%=Model.Localize("Entry.Error") %>');
              }
          });
      }
      function showEditAlbum(id) {
          $.ajax({
              url: '<%=Url.Action("ShowUpdate","Albums",new{id="albumId"}) %>'.replace('albumId', id.toString()),
              metehod: 'post',
              dataType: 'html',
              success: function(t) {
                  document.getElementById('editAlbumDivContent').innerHTML = t;
                  $('#UpdateAlbumForm').validate();
                  document.getElementById('editAlbumDivTopContent').innerHTML = '<%=Model.Localize("Edit")%>';
                  $('#editAlbumDiv').show();
                  document.getElementById('returnUrl').value = '<%=Html.Encode(Request.RawUrl) %>';
                  
              }, error: function(err) {
                  alert('<%=Model.Localize("Entry.Error") %>');
              }
          });
      }
        -->
    </script>
       
    <div class="window" id="editAlbumDiv">
	<div class="windowTop" id="editAlbumDivTop" style="background-image:url(<%=Html.ThemeItem("window_top_end.png")%>);">
		<div class="windowTopContent" id="editAlbumDivTopContent" style="background-image:url(<%=Html.ThemeItem("window_top_start.png")%>);">
		</div><img class="windowClose" src="<%=Html.ThemeItem("window_close.jpg")%>" id="editAlbumDivClose" onclick="$('#editAlbumDiv').hide()" alt="missing label :Close" />
	</div><div class="windowBottom" id="editAlbumDivBottom" style="background-image:url(<%=Html.ThemeItem("window_bottom_end.png")%>);">
		<div class="windowBottomContent" id="editAlbumDivBottomContent" style="background-image:url(<%=Html.ThemeItem("window_bottom_start.png")%>);">
			&nbsp;
		</div>
	</div><div class="windowContent" id="editAlbumDivContent">
	</div><img class="windowResize" src="<%=Html.ThemeItem("window_resize.gif")%>" id="editAlbumDivResize" alt="" />
</div> <script type="text/javascript">
<!--
           $(document).ready(
	function() {
	    $('#editAlbumDiv').Resizable(
			{
			    minWidth: 200,
			    minHeight: 200,
			    maxWidth: 600,
			    maxHeight: 800,
			    dragHandle: '#editAlbumDivTop',
			    handlers: {
			        se: '#editAlbumDivResize'
			    },
			    onResize: function(size, position) {
			        $('#editAlbumDivBottom, #editAlbumDivBottomContent').css('height', size.height - 33 + 'px');
			        var windowContentEl = $('#editAlbumDivContent').css('width', size.width - 25 + 'px');
			        if (!document.getElementById('editAlbumDiv').isMinimized) {
			            windowContentEl.css('height', size.height - 48 + 'px');
			        }
			    }
			}
		);
	}
);
-->
</script>
<%} %>
</asp:Content>
